#!/usr/bin/env python
# -*- coding: utf-8 -*-

# subscribe mymessage
import sys
import rospy
import cv2
from std_msgs.msg import String
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
import time


def call_back(data):
    try:
        bridge = CvBridge()
        cv_image = bridge.imgmsg_to_cv2(data,  'rgb8')
        cv2.imwrite('/home/smile/catkin_ws/src/test0501/script/yolov5-master/data/images/1.jpg', cv_image)
        cv2.imshow('src', cv_image)
        cv2.waitKey(1)
    except e:
        print(e)


if __name__ == '__main__':

    rospy.init_node('take_photo', anonymous= False)
    img_topic = '/camera/rgb/image_raw'
    image_sub = rospy.Subscriber(img_topic, Image, call_back)
    rospy.spin()

